package CalendarComponents;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * Class representing a Reminder Item with a label for displaying the type of reminder, length and units of time and a close-button with a small icon
 * The instance erases itself from the list by calling a parent routine
 * @author Christian G.
 */
@SuppressWarnings("serial")
public class ReminderItem extends JPanel implements ActionListener{

	private Reminder reminder;
	private JLabel label;
	private JButton closeButton;
	private PropertiesDialog parentDialog;
	
	/**
	 * Constructor using an object of type Reminder
	 * @param r an object of type Reminder
	 * @param parent the parent PropertiesDialog instance
	 */
	public ReminderItem(Reminder r, PropertiesDialog parent){
		
		reminder = r;
		String type = r.getType();
		String units = r.getUnits();
		int length = r.getLength();
		
		String text = type + ": " + length + " " + units + " before";
		label = new JLabel(text);
		//Box-Layout of the parent JPanel cares about those properties (at least should care)
		label.setPreferredSize(new Dimension(200,10));
		label.setMaximumSize(new Dimension(200,10));
		
		ImageIcon closeIcon = new ImageIcon("close-icon.png");
		closeButton = new JButton();
		closeButton.addActionListener(this);
		closeButton.setIcon(closeIcon);
		
		this.parentDialog = parent;
		
		this.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
		this.setBackground(Color.WHITE);
		this.setLayout(new BorderLayout());
		this.add(label,BorderLayout.WEST);
		this.add(closeButton,BorderLayout.EAST);
	}
	
	/**
	 * Constructor defining a reminder
	 * @param type the type of reminder as specified by the static attributes
	 * @param units
	 * @param length
	 * @param parent
	 */
	public ReminderItem(String type, String units, int length, PropertiesDialog parent){
		
	}
	
	public void setEnabled(boolean enabled){
		System.out.println("Set enabled called!");
		this.label.setEnabled(enabled);
		this.closeButton.setEnabled(enabled);
	}

	/**
	 * Used by the "delete"-button. Call the method of the dialog parent to erase this instance itself from the panel it is on(non-Javadoc)
	 */
	public void actionPerformed(ActionEvent e) {
		
		parentDialog.removeReminderItem(this);
		
	}

	public Reminder getReminder() {
		return reminder;
	}

	public void setReminder(Reminder reminder) {
		this.reminder = reminder;
	}
	
}
